<?php
namespace app\index\controller;

class User
{
    public function login()
    {
        return view('');
    }

    public function register()
    {
        if(request()->isGet()) {
            return view('');
        }
        if(request()->isPost()) {
            $data = input('post.');
            $validate = validate('User');
            if( $validate -> check( $data ) ) {
                $user = model('User');
                $user -> data([
                    'email'     => $data['email'],
                    'username'  => $data['username'],
                    'create_ip' => request() -> ip(),
                    'password'  => password($data['email'].$data['password']),
                ]);
                if(! $user -> save()) {
                    return $user -> getError();
                } else {
                    session('email', $data['email']);
                    return 'success!';
                }
            } else {
                return $validate -> getError();
            }
        }
    }

}
